-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make mx.compile work on Windows #1697
base: main
Are you sure you want to change the base?
Conversation
mlx/backend/common/compiled_cpu.cpp
Outdated
#ifdef _MSC_VER | ||
const VisualStudioInfo& info = GetVisualStudioInfo(); | ||
std::string libpaths; | ||
for (const std::string& lib : info.libpaths) { | ||
libpaths += fmt::format(" /libpath:\"{0}\"", lib); | ||
} | ||
std::string build_command = fmt::format( | ||
"\"" | ||
"cd /D \"{0}\" && " | ||
"\"{1}\" /LD /EHsc /MD /Ox /nologo /std:c++17 \"{2}\" " | ||
"/link /out:\"{3}\" {4} >nul" | ||
"\"", | ||
std::filesystem::temp_directory_path().string(), | ||
info.cl_exe, | ||
source_file_name.str(), | ||
shared_lib_name.str(), | ||
libpaths); | ||
#else | ||
std::string build_command = fmt::format( | ||
"g++ -std=c++17 -O3 -Wall -fPIC -shared '{0}' -o '{1}'", | ||
source_file_path, | ||
shared_lib_path); | ||
#endif | ||
auto return_code = system(build_command.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to encapsulated the compiler into it's own class to contain the if-defs and make this more maintainable / extensible.
Something like:
static std::string JitCompiler::build_command(
const std::string& source_file_path, const std::string& shared_lib_name)
// And we could include any special source code headers needed in the class as well.
static std::string JitCompiler::get_header()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then again.. we only have three compilers (g++, clang, msvc) right now.. so I'm also ok to wait and see if we need to generalize this again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good timing to move the code to a separate file, I have updated the PR.
Refs #1513.
This PR adds code to invoke MSVC on Windows. Most of the new code are about getting the paths information of Visual Studio.